package com.qxzn.app.page.util;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.maning.imagebrowserlibrary.MNImageBrowser;
import com.maning.imagebrowserlibrary.listeners.OnClickListener;
import com.maning.imagebrowserlibrary.listeners.OnLongClickListener;
import com.maning.imagebrowserlibrary.listeners.OnPageChangeListener;
import com.maning.imagebrowserlibrary.model.ImageBrowserConfig;
import com.qxzn.app.page.R;

import java.util.ArrayList;

public class ImageUtil {

    public static void viewImg(Context context, ArrayList<String> imgList, View view, int position) {
        View customView = LayoutInflater.from(context).inflate(R.layout.bg_picture_viewer, null);
        ImageView ic_close = (ImageView) customView.findViewById(R.id.iv_close);
        final TextView tv_position = (TextView) customView.findViewById(R.id.tv_position);
        LinearLayout ll_delete = (LinearLayout) customView.findViewById(R.id.ll_delete);
        LinearLayout ll_download = (LinearLayout) customView.findViewById(R.id.ll_download);
        ic_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //关闭图片浏览
                MNImageBrowser.finishImageBrowser();
            }
        });
        ll_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //删除当前位置的图片
                MNImageBrowser.removeCurrentImage();
                //刷新指示器
                tv_position.setText((MNImageBrowser.getCurrentPosition() + 1) + "/" + MNImageBrowser.getImageList().size());
            }
        });
        ll_download.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        tv_position.setText((position + 1) + "/" + imgList.size());

        MNImageBrowser.with(context)
                //必须-当前位置
                .setCurrentPosition(position)
                //必须-图片加载用户自己去选择
                .setImageEngine(new GlideImageEngine())
                //必须（setImageList和setImageUrl二选一，会覆盖）-图片集合
                .setImageList(imgList)
                //必须（setImageList和setImageUrl二选一，会覆盖）-设置单张图片
//                .setImageUrl("xxx")
                //非必须-图片切换动画
                .setTransformType(ImageBrowserConfig.TransformType.Transform_Default)
                //非必须-指示器样式（默认文本样式：两种模式）
                .setIndicatorType(ImageBrowserConfig.IndicatorType.Indicator_Number)
                //设置隐藏指示器
                .setIndicatorHide(false)
                //设置自定义遮盖层，定制自己想要的效果，当设置遮盖层后，原本的指示器会被隐藏
                .setCustomShadeView(customView)
                //自定义ProgressView，不设置默认默认没有
                .setCustomProgressViewLayoutID(R.layout.layout_custom_progress_view)
                //非必须-屏幕方向：横屏，竖屏，Both（默认：横竖屏都支持）
                .setScreenOrientationType(ImageBrowserConfig.ScreenOrientationType.Screenorientation_Default)
                //非必须-图片单击监听
                .setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(FragmentActivity activity, ImageView view, int position, String url) {
                        //单击监听
                    }
                })
                //非必须-图片长按监听
                .setOnLongClickListener(new OnLongClickListener() {
                    @Override
                    public void onLongClick(FragmentActivity activity, ImageView imageView, int position, String url) {
                        //长按监听
                    }
                })
                //非必须-图片滑动切换监听
                .setOnPageChangeListener(new OnPageChangeListener() {
                    @Override
                    public void onPageSelected(int position) {
                        //图片滑动切换监听
                        tv_position.setText((position + 1) + "/" + imgList.size());
                    }
                })
                //全屏模式：默认非全屏模式
//                .setFullScreenMode(isFulScreenMode)
                //手势下拉缩小效果是否开启
                .setOpenPullDownGestureEffect(true)
                //打开动画
                .setActivityOpenAnime(R.anim.mn_browser_enter_anim)
                //关闭动画
                .setActivityExitAnime(R.anim.mn_browser_exit_anim)
                //打开
                .show(view);
    }

}
